package org.jeecg.modules.system.mapper;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysDepartPosition;
import org.jeecg.modules.system.model.SysDepartTreeModel;
import org.jeecg.modules.system.model.TreeModel;

import java.util.List;

/**
 * <p>
 * 部门 Mapper 接口
 * <p>
 * 
 * @Author: Steve
 * @Since：   2019-01-22
 */
public interface SysDepartMapper extends BaseMapper<SysDepart> {
	
	/**
	 * 根据用户ID查询部门集合
	 */
	public List<SysDepart> queryUserDeparts(@Param("userId") String userId);

	/**
	 * 查询用户id是否为管理处
	 * @param id
	 * @return
	 */
	public Integer selectMange(String id);

	public List<SysDepart> queryUserTreeList();
	List<SysDepart> queryDepartTreeListOa();
	public List<SysDepart> queryDepartTreeList();
	@Select("select parent_id from sys_depart where id = #{id} and del_flag='0'")
	String selectParentId(@Param("id")String id);

	@SqlParser(filter = true)
    List<SysDepart> findAll();

	@SqlParser(filter = true)
	SysDepart get(String departId);

	@Select("select * from sys_depart  where org_code = #{code} and del_flag='0'")
	SysDepart selectDepartCode(@Param("code")String code);
    @Select("select position_id from sys_depart_position where depart_id =#{departId} and del_flag='0'")
    List<String> queryDepartPositionList(@Param("departId") String departId);
	@Select("SELECT id,parent_id as parentId FROM sys_depart WHERE id = (SELECT depart_id FROM sys_user WHERE id = #{userId})")
    SysDepart queryDepartId(String userId);

    List<SysDepart> findChildsByParentIds(String parentIds);

    void updateBatchById(@Param("list") List<SysDepart> childDepartList);

    List<SysDepart> findChildByParentIdAndName(@Param("parentId") String parentId,@Param("departId") String departId,@Param("departName") String departName);

	@Select("SELECT `code` FROM base_project WHERE id = #{projectId} AND del_flag = '0'")
	String getProjectCode(@Param("projectId") String projectId);

	@Select("SELECT depart_id FROM base_project WHERE id = #{projectId} AND del_flag = '0'")
	String selectOfficeByProjectId(String projectId);

	SysDepart getDepartName(@Param("projectId") String projectId);


	//------------------------------------S端-START--------------------------------------------------
	@SqlParser(filter = true)
    List<SysDepart> queryServerTreeList(String tenantId);
	@SqlParser(filter = true)
    void serverSave(@Param("bean") SysDepart sysDepart);
	@SqlParser(filter = true)
	List<SysDepart> querySubTreeByParentId(@Param("bean") SysDepart sysDepart);
	@SqlParser(filter = true)
	SysDepart getServerById(@Param("tenantId") String tenantId, @Param("id") String id);
	@SqlParser(filter = true)
	int serverCountChild(@Param("tenantId") String tenantId,@Param("parentId") String parentId,@Param("departName") String departName);
	@SqlParser(filter = true)
    void serverUpdateName(@Param("id") String id,@Param("name") String name);

    //------------------------------------S端-END----------------------------------------------------
}
